import { Game } from "@sapi-game/main";
import { DirtShopMapLoader } from "../components/loader";
import { DirtShopMoudle } from "../module";
import { EffectIds } from "@sapi-game/utils/vanila-data";
import { GameMode } from "@minecraft/server";
import { DirtShopMainState } from "./mainState";

export class DirtShopLoadState extends DirtShopMoudle.State {
    protected override onEnter(): void {
        this.addComponent(DirtShopMapLoader);
        this.initPlayer();

        //循环给治疗
        this.subscribe(Game.events.interval, () => {
            this.context.groupSet.forEach((p) => {
                p.addEffect(EffectIds.InstantHealth, 20, 10);
            });
        });
    }

    initPlayer() {
        this.context.groupSet.forEach((p) => {
            p.player.setGameMode(GameMode.Survival);
            p.clear();
            p.runCommand("effect @s clear");
            p.player.teleport(this.context.map.loadPos);
        });
    }

    next() {
        this.transitionTo(DirtShopMainState);
    }
}
